mini.parse();

function TransferGoodsHandler() {
};

TransferGoodsHandler.instance = new TransferGoodsHandler();

TransferGoodsHandler.bggLeftTree = mini.get("bggLeftTree");
TransferGoodsHandler.bggRightTree = mini.get("bggRightTree");
TransferGoodsHandler.gData = null;
TransferGoodsHandler.gLeftBggPid = null;
TransferGoodsHandler.gRightBggPid = null;

/**
 * 标准方法接口定义
 * @param {} data
 */
TransferGoodsHandler.passData = function(data) {
    if (data != null && data.rowData != null) {
        data = mini.clone(data);
        //动态加载节点时，需同时设置setValue，setText，且必须先setValue，然后再setText
        TransferGoodsHandler.bggLeftTree.setValue(data.rowData.bggId);
    	TransferGoodsHandler.bggLeftTree.setText(data.rowData.bggName);
    	TransferGoodsHandler.bggRightTree.setValue(data.rowData.bggId);
    	TransferGoodsHandler.bggRightTree.setText(data.rowData.bggName);
    	TransferGoodsHandler.gData = data.rowData;
    }
}

TransferGoodsHandler.getParentBggInfo = function(leftBggId, rightBggId){
 	$.ajax({ 
        url: __root + "/getGoodsGroupInfoById.do?bggId=" + leftBggId,
        cache: false,
        dataType: 'json',
        success: function (bggInfo) {
        	if(bggInfo.bggParent != null 
        		&& bggInfo.bggParent != "undefined"
        		&& bggInfo.bggParent != "0"){
        			TransferGoodsHandler.gLeftBggPid = bggInfo.bggParent;
        	}else{
					TransferGoodsHandler.gLeftBggPid = "0";
        	}
        }
    });
    
    $.ajax({ 
        url: __root + "/getGoodsGroupInfoById.do?bggId=" + rightBggId,
        cache: false,
        dataType: 'json',
        success: function (bggInfo) {
        	if(bggInfo.bggParent != null 
        		&& bggInfo.bggParent != "undefined"
        		&& bggInfo.bggParent != "0"){
        			TransferGoodsHandler.gRightBggPid = bggInfo.bggParent;
        	}else{
					TransferGoodsHandler.gRightBggPid = "0";
        	}
        }
    });
}

/**
 * 转移商品
 */
TransferGoodsHandler.transfer = function(){
	var leftBggId = TransferGoodsHandler.bggLeftTree.getValue();
	var rightBggId = TransferGoodsHandler.bggRightTree.getValue();
	
	if(((leftBggId == TransferGoodsHandler.gData.bggId) 
		&& (rightBggId == TransferGoodsHandler.gData.bggId)) 
			|| (leftBggId == rightBggId)){
		mini.alert("转移项内容不变，请重新设置！","系统提示",null);
		return;
	}
	
	TransferGoodsHandler.getParentBggInfo(leftBggId, rightBggId);
	
//	alert(TransferGoodsHandler.gLeftBggPid + "==" + TransferGoodsHandler.gRightBggPid);
	if(TransferGoodsHandler.gLeftBggPid != TransferGoodsHandler.gRightBggPid 
		|| (TransferGoodsHandler.gLeftBggPid == "0" 
			&& TransferGoodsHandler.gRightBggPid == "0")){
		mini.confirm("转移项层级发生变化，确认转移？", "系统提示？",
            function (action) {            
                if (action == "ok") {
                    TransferGoodsHandler.doTtransfer(leftBggId, rightBggId);
                } 
            }
        );
	}else{
		TransferGoodsHandler.doTtransfer(leftBggId, rightBggId);
	}
}

/**
 * 执行转移
 * @param {} leftBggId
 * @param {} rightBggId
 */
TransferGoodsHandler.doTtransfer = function(leftBggId, rightBggId){
	 /*var transferWarning = document.getElementById("transferWarning");
     transferWarning.style.display = "";
     mini.showMessageBox({
        width: 250,
        title: "系统提示",
        message: "系统提示",
        showCloseButton:false,
        html: transferWarning
    });
	
    setTimeout(function () {
    	mini.hideMessageBox();
    },3000);*/
	 mini.alert("尚未开发，敬请期待！","系统提示");
    
}


/**
 * 重置数据
 */
TransferGoodsHandler.reset = function(){
	TransferGoodsHandler.bggLeftTree.load(__root + "/lazyLoadGoodsGroupTree.do");
	TransferGoodsHandler.bggRightTree.load(__root + "/lazyLoadGoodsGroupTree.do");
	
	TransferGoodsHandler.bggLeftTree.setValue(TransferGoodsHandler.gData.bggId);
	TransferGoodsHandler.bggLeftTree.setText(TransferGoodsHandler.gData.bggName);
	TransferGoodsHandler.bggRightTree.setValue(TransferGoodsHandler.gData.bggId);
	TransferGoodsHandler.bggRightTree.setText(TransferGoodsHandler.gData.bggName);
	TransferGoodsHandler.gLeftBggPid = null;
	TransferGoodsHandler.gRightBggPid = null;
}

/**
 * 关闭窗口
 * @param {} action
 */
TransferGoodsHandler.closeCurrentWin = function(action) {
    if (window.CloseOwnerWindow) window.CloseOwnerWindow(action);
    else window.close();
}

TransferGoodsHandler.closeMiniWin = function(){
	TransferGoodsHandler.closeCurrentWin("cancel");
}